"""
@File         : router.py
@Time         : 2024/05/09 18:14:10
@Author       : Qrj
@Email        : 923207736@qq.com
@Description  : 站内信模板相关路由
"""

from typing import Annotated

from fastapi import APIRouter, Depends

from src.business.admin.system.oauth2.token.dependencies.no_introduction import (
    DependVerifyAccessTokenMenumPermission,
)
from src.enums.permission_operation import PermissionOperationEnum
from src.utils.unified_response import SuccessApiJSONResponse

from .dependencies.route_depend import (
    route_depend_create_station_message_template,
    route_depend_delete_station_message_template,
    route_depend_get_station_message_template,
    route_depend_list_station_message_template,
    route_depend_send_test_station_message,
    route_depend_update_station_message_template,
    route_depend_update_station_message_template_status,
)
from .schemas.out import StationMessageTemplateCompleteOutSchema

# 构建权限验证相关的依赖项
# 查
depend_select_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.select.value
)
# 增
depend_create_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.create.value
)
# 改
depend_update_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.update.value
)
# 删
depend_delete_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.delete.value
)
# 发送站内信测试消息
depend_send_test_station_message_permission_verify = (
    DependVerifyAccessTokenMenumPermission(
        __file__, PermissionOperationEnum.send_test_station_message.value
    )
)


# 创建路由
router = APIRouter(
    prefix="/admin/system/station-message/template",
    tags=[
        "站内信模板接口",
    ],
)


@router.get("/get", summary="查询单个站内信模板")
async def route_get_station_message_template(
    verify_menu_permission: Annotated[None, Depends(depend_select_permission_verify)],
    station_message_template: Annotated[
        StationMessageTemplateCompleteOutSchema,
        Depends(route_depend_get_station_message_template),
    ],
):
    return SuccessApiJSONResponse(data=station_message_template)


@router.post("/list", summary="查询站内信模板列表")
async def route_list_station_message_template(
    verify_menu_permission: Annotated[None, Depends(depend_select_permission_verify)],
    list_result: Annotated[
        tuple[list[StationMessageTemplateCompleteOutSchema], int],
        Depends(route_depend_list_station_message_template),
    ],
):
    search_pagination_result, search_total = list_result
    data = {"result": search_pagination_result, "total": search_total}
    return SuccessApiJSONResponse(data=data)


@router.post("/create", summary="创建站内信模板")
async def route_create_station_message_template(
    # 验证用户权限(本菜单权限标识为: admin@system@station_message_template:create)
    verify_menu_permission: Annotated[None, Depends(depend_create_permission_verify)],
    created_id: Annotated[int, Depends(route_depend_create_station_message_template)],
):
    data = {"created_id": created_id}
    return SuccessApiJSONResponse(message="站内信模板创建成功", data=data)


@router.post("/update", summary="修改站内信模板")
async def route_update_station_message_template(
    verify_menu_permission: Annotated[None, Depends(depend_update_permission_verify)],
    update_operation: Annotated[
        None, Depends(route_depend_update_station_message_template)
    ],
):
    return SuccessApiJSONResponse(message="修改站内信模板成功")


@router.post("/update-status", summary="修改站内信模板状态")
async def route_update_station_message_template_status(
    verify_menu_permission: Annotated[None, Depends(depend_update_permission_verify)],
    update_status_operation: Annotated[
        None, Depends(route_depend_update_station_message_template_status)
    ],
):
    return SuccessApiJSONResponse(message="修改站内信模板状态成功")


@router.post("/delete", summary="删除站内信模板")
async def route_delete_station_message_template(
    verify_menu_permission: Annotated[None, Depends(depend_delete_permission_verify)],
    delete_operation: Annotated[
        None, Depends(route_depend_delete_station_message_template)
    ],
):
    return SuccessApiJSONResponse(message="删除站内信模板成功")


@router.post("/send", summary="发送站内信测试消息")
async def route_send_test_station_message(
    verify_menu_permission: Annotated[
        None, Depends(depend_send_test_station_message_permission_verify)
    ],
    send_operation: Annotated[None, Depends(route_depend_send_test_station_message)],
):
    return SuccessApiJSONResponse(message="发送站内信测试消息成功")
